import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))





def get_db_url(dbinfo):
    engine = dbinfo.get("ENGINE") or "sqlite"
    driver = dbinfo.get("DRIVER") or "sqlite"
    user = dbinfo.get("USER") or ""
    password = dbinfo.get("PASSWORD") or ""
    host = dbinfo.get("HOST") or ""
    port = dbinfo.get("PORT") or ""
    name = dbinfo.get("NAME") or ""
    s = "{}+{}://{}:{}@{}:{}/{}".format(engine, driver, user, password, host, port, name)
    print(s)
    return "{}+{}://{}:{}@{}{}/{}".format(engine, driver, user, password, host, port, name)


class Config:
    DEBUG = False
    TEST = False
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True


class DevelopConfig(Config):
    DEBUG = True

    dbinfo = {
        "ENGINE": "mysql",
        "DRIVER": "pymysql",
        "USER": "root",
        "PASSWORD": "123456",
        "HOST": "10.0.0.200",
        "PORT": "3306",
        "NAME": "test"
    }

    SQLALCHEMY_DATABASE_URL = get_db_url(dbinfo)




class TestConfig(Config):
    TEST = True

    dbinfo = {
        "ENGINE": "mysql",
        "DRIVER": "pymysql",
        "USER": "root",
        "PASSWORD": "123456",
        "HOST": "",
        "PORT": "3306",
        "NAME": "test"
    }

    SQLALCHEMY_DATABASE_URL = get_db_url(dbinfo)


envs = {"development":DevelopConfig,
        "testing":TestConfig,
        "default":DevelopConfig

        }